package com.gowants.pems.service;

import com.gowants.pems.mapper.EquipmentMapper;
import com.gowants.pems.mapper.EquipmentScrapMapper;
import com.gowants.pems.model.Equipment;
import com.gowants.pems.model.EquipmentScrap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ScrapService {

    @Autowired
    private EquipmentScrapMapper mapper;

    @Autowired
    private EquipmentMapper eMapper;

    public int saveEquipmentScrap(EquipmentScrap record){
        int i=0;
        i=mapper.insert(record);
        return i;
    }

    @Transactional(rollbackFor = {Exception.class})
    public int editEquipmentScrap(EquipmentScrap record){
        int i=0;
        i=mapper.update(record);
        if(record.getState()==1) {
            Equipment equipment1 = new Equipment();
            equipment1.setId(record.getEquipmentId());
            equipment1.setState(3);
            eMapper.update(equipment1);
        }
        return i;
    }
}
